home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / dbkit / DBDatabase.h < prev    next >
Text File  |  1994-05-09  |  6KB  |  218 lines

  1. /*
  2. **      DBDatabase.h
  3. **      Database Kit, Release 3.0
  4. **      Copyright (c) 1992, NeXT Computer, Inc.  All rights reserved. 
  5. */
  6.  
  7. #import <objc/Object.h>
  8. #import <ansi/stdarg.h>
  9. #import <dbkit/protocols.h>
  10. #import <mach/cthreads.h>
  11.  
  12. @class List;
  13. @class DBBinder;
  14.  
  15. /*
  16. ** A Database represents a (potential) connection to an external source of
  17. **  data.  It also represents structural information about that source of
  18. **  data.  This structural information is represented as a list of properties.
  19. **  (See the protocols header for a description of a property.)
  20. **
  21. ** Properties can either be built from scratch by a tool or by a program, or
  22. **  they can be provided by the DBDatabase.  In the latter case, the complexity
  23. **  and completeness of the data dictionary is totally dependant upon the
  24. **  database; most will produce a very simple model which reflects their 
  25. **  structure.
  26. **
  27. ** Given an expressive enough query language, properties can also be built
  28. **  by using DBExpressions -- aggregate and compound properties can be built
  29. **  this way.
  30. */
  31.  
  32. @interface DBDatabase : Object
  33. {
  34. @public
  35.   id delegate;
  36.  
  37. @private
  38.   id _adaptor;
  39.   mutex_t _adaptorLock;
  40.  
  41.   id _entityList;
  42.   id _bundle;
  43.   id _strings;
  44.  
  45.   id _databaseNameString;
  46.   char *_namebuf;
  47.   id _identityProperty;
  48.  
  49.   id _private;
  50.   struct {
  51. #if    __BIG_ENDIAN__
  52.     BOOL connected:1;
  53.     BOOL panelsEnabled:1;
  54.     BOOL delegateDoesTrace:1;
  55.     BOOL delegateChecksQuery:1;
  56.     BOOL transactionInProgress:1;
  57.     BOOL useOuterJoins:1;
  58.     BOOL isAsciiFormat:1;
  59.     BOOL spuriousRollback:1;
  60.     int _RESERVED:8;
  61. #else    __BIG_ENDIAN__
  62.     int _RESERVED:8;
  63.     BOOL spuriousRollback:1;
  64.     BOOL isAsciiFormat:1;
  65.     BOOL useOuterJoins:1;
  66.     BOOL transactionInProgress:1;
  67.     BOOL delegateChecksQuery:1;
  68.     BOOL delegateDoesTrace:1;
  69.     BOOL panelsEnabled:1;
  70.     BOOL connected:1;
  71. #endif    __BIG_ENDIAN__
  72.   } _flags;
  73.   NXZone *_garbageZone;
  74. }
  75.  
  76. + initialize;
  77.  
  78. /*
  79. ** If there is an open db with this name, it is returned.  If there is a
  80. **  database file in the search path with this name, it is opened and a
  81. **  connection is attempted.  If the connection attempt fails, the 
  82. **  database is freed, so subsequent calls will attempt to connect again,
  83. **  possibly using new information...
  84. **
  85. ** Databases found using this method should not be freed!
  86. */
  87. + findDatabaseNamed:(const char*)aName connect:(BOOL)yn;
  88.  
  89. /*
  90. ** Databases can use database "bundles" that reside in the filesystem to
  91. **  initialize themselves with user and schema information.  The documents are
  92. **  directories (with a file extension of .db) that contain at least two
  93. **  files: db.strings and db.archive.
  94. **
  95. ** Within the bundle, db.strings is a stringTable that can contain a string
  96. **  with the key "AdaptorName".  It can also contain multiple initStrings,
  97. **  indexed by username.  A key of "LoginString" will be used as a default
  98. **  loginString.
  99. */
  100. + (const char**)databaseNamesForAdaptor:(const char*)anAdaptorName;
  101. + (const char**)adaptorNames;
  102.  
  103. - initFromFile:(const char*)aPath;
  104. - (const char*)directory;
  105.  
  106. - (const char*)name;
  107. - (BOOL)setName:(const char*)aName;
  108.  
  109. - adaptor;
  110.  
  111. - (BOOL)connect;
  112. - (BOOL)disconnect;
  113. - (BOOL)connectUsingString:(const unsigned char*)aString;
  114. - (BOOL)disconnectUsingString:(const unsigned char*)aString;
  115.  
  116. - (BOOL)isConnected;
  117. - (const unsigned char*)connectionName;
  118.  
  119. - (BOOL)beginTransaction;
  120. - (BOOL)commitTransaction;
  121. - (BOOL)rollbackTransaction;
  122.  
  123. - (BOOL)isTransactionInProgress;
  124. - (BOOL)enableTransactions:(BOOL)yn;
  125. - (BOOL)areTransactionsEnabled;
  126.  
  127. - (BOOL)evaluateString:(const unsigned char*)aString, ...;
  128.  
  129. - (List*)getEntities:(List*)aList;
  130. - (id<DBEntities>)entityNamed:(const char*)aName;
  131.  
  132. /*
  133. ** These can be used to find information specific to the current db bundle.
  134. */
  135. - (const char*)currentAdaptorName;
  136. - (const char*)defaultAdaptorName;
  137. - (const unsigned char*)currentLoginString;
  138. - (const unsigned char*)defaultLoginString;
  139. - (const unsigned char*)loginStringForUser:(const char*)aUser;
  140.  
  141. /*
  142. ** This can be used to launch a login panel, or to use a specific adaptor
  143. **  in the context of a database.  The init string can be NULL.
  144. */
  145. - (BOOL)connectUsingAdaptor:(const char*)aClassname
  146.     andString:(const unsigned char*)aLoginString;
  147.  
  148. /*
  149. ** -emptyDataDictionary will free up the currently loaded data dictionary
  150. **  so that another can be opened for the db.  -loadDefaultDataDictionary
  151. **  will attempt to load a data dictionary from the adaptor if one is
  152. **  not already loaded.
  153. */
  154. - emptyDataDictionary;
  155. - loadDefaultDataDictionary;
  156.  
  157. /*
  158. ** Delegate can act as trace of execution, log all query expressions, or
  159. **  verify query expressions. It can also override commits and aborts.
  160. */
  161. - setDelegate:aDelegate;
  162. - delegate;
  163.  
  164. /* to be called only from db:notificationFrom:message:code: in the
  165. ** case that the delegate discovers that a database event (e.g.
  166. ** trigger or stored procedure) has premptively caused a rollback
  167. ** to occur on the server.  DBKit can often not detect such cases.
  168. */
  169. - notifyServerDidRollback;
  170.  
  171. @end
  172.  
  173. @interface Object (DatabaseDelegate)
  174.  
  175. /*
  176. ** Commit/abort verification -- no cancelling allowed!
  177. */
  178. - dbWillCommitTransaction:aDatabase;
  179. - dbDidCommitTransaction:aDatabase;
  180. - dbWillRollbackTransaction:aDatabase;
  181. - dbDidRollbackTransaction:aDatabase;
  182.  
  183. /*
  184. ** Query interposition -- before evaluating an expression, the delegate can
  185. **  be given the chance to override a query expression, to examine it, or
  186. **  to replace it.
  187. */
  188. - (BOOL)db:aDb willEvaluateString:(const unsigned char*)aString
  189.      usingBinder:aBinder;
  190.  
  191. /*
  192. ** Logging -- the delegate receives a printf style format string and
  193. **  arguments, to be used with vsprintf().
  194. */
  195. - db:aDatabase log:(const char*)fmt, ...;
  196.  
  197. /*
  198. ** Notification -- an object being used by the database has encountered
  199. **  an exceptional situation.
  200. **
  201. ** By providing a delegate that responds to this method, the default alert
  202. **  panels can be squelched.
  203. */
  204. - (BOOL)db:aDb notificationFrom:anObject
  205.      message:(const unsigned char*)msg code:(int)n;
  206.  
  207. /*
  208. ** setPanelsEnabled:NO must be called if you plan to use the DBDatabase
  209. **  without panels or windows, or in a program without an Application object.
  210. */
  211. - (BOOL)arePanelsEnabled;
  212. - setPanelsEnabled:(BOOL)yn;
  213.  
  214. - read:(NXTypedStream*)ts;
  215. - write:(NXTypedStream*)ts;
  216.  
  217. @end
  218.